package cn.hs.controller;

import cn.hs.entity.Appointment;
import cn.hs.service.AppointmentService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * @ClassName AppointmentController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月24日 10:40
 * @Version 1.0
 */
@RestController
@RequestMapping("/appointment")
public class   AppointmentController {
    @Autowired
    private AppointmentService service;
    @GetMapping("/selectAll")
    public Object selectAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize
    ){
        PageInfo<Appointment> pageInfo = service.selectAll(pageNum, pageSize);
        return Result.success(pageInfo);
    }
    @GetMapping("/selectById")
    public Object selectById(Appointment appointment){
        Appointment appointment1 = service.selectById(appointment);
        if(appointment1!=null){
            return Result.success(appointment1);
        }else {
            return Result.error("暂无数据");
        }
    }
    @GetMapping("/selectByConsultId")
    public Object selectByConsultId(
            @RequestParam Integer consultId
    ){
        List<Appointment> appointments = service.selectByConsultId(consultId);
        if(appointments!=null){
            return Result.success(appointments);
        }else {
            return Result.error("暂无数据");
        }
    }
    @GetMapping("/selectByUserId")
    public Object selectByUserId(
            @RequestParam Integer userId
    ){
        List<Appointment> appointments = service.selectByUserId(userId);
        if(appointments!=null){
            return Result.success(appointments);
        }else {
            return Result.error("暂无数据");
        }
    }
    @PostMapping("/insert")
    public Object insert(@RequestBody Appointment appointment){
        appointment.setCreatetime(new Date());
        int insert = service.insert(appointment);
        if(insert!=0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }
    @PostMapping("/delete")
    public Object delete(@RequestBody Appointment appointment){
        int delete = service.delete(appointment);
        if(delete!=0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    @PostMapping("/updateStatus")
    public Object updateStatus(@RequestBody Appointment appointment){
        int update = service.update(appointment);
        if(update!=0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
    @PostMapping("/updateReply")
    public Object updateReply(@RequestBody Appointment appointment){
        int update = service.updateReply(appointment);
        if(update!=0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
}
